﻿using System;
using System.Data;

namespace org.se.fs.model.Table
{
    public class User : DataContext
    {
        public DataTable GetUserById(UInt64 id)
        {
            using (var databaseManager = GetDatabase())
            {
                databaseManager.Open();
                databaseManager.CreateParameters(1);
                databaseManager.AddParameters(0, "id", id);
                var dataSet = databaseManager.ExecuteDataSet(CommandType.StoredProcedure, "GetUserById");
                return ToDataTable(dataSet);
            }
        }

        public UInt64 GetUserId(string username, string userpass)
        {
            using (var databaseManager = GetDatabase())
            {
                databaseManager.Open();
                databaseManager.CreateParameters(2);
                databaseManager.AddParameters(0, "username", username);
                databaseManager.AddParameters(1, "userpass", userpass);
                var result = databaseManager.ExecuteScalar(CommandType.StoredProcedure, "GetUserId");
                return string.IsNullOrEmpty(result.ToString()) ? 0 : Convert.ToUInt64(result);
            }
        }
    }
}
